package server.service;

import common.User;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class SocketThreadManager {
    private static HashMap<String,UserThread> users=new HashMap<>();

    public static void addUserThread(String userId,UserThread userThread){
users.put(userId,userThread);
    }
    public static UserThread getUserThread(String userID){
        return users.get(userID);
    }
    public static boolean isExitUser(String userId){
        if(users.get(userId)==null)return false;
        return true;
    }
    public static String getOnlineUser(String requestUser){
        Iterator<String> iterator = users.keySet().iterator();
        String userList="";
        String temp="";
        while(iterator.hasNext()){
           if((temp=iterator.next())!=requestUser){
               userList+=temp+" ";
           }
        }
        return userList;
    }
    public static void removeUserThread(String userId){
        users.remove(userId);
    }

    public static HashMap<String, UserThread> getUsers() {
        return users;
    }
}
